package com.undsf.utility;

import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * Created by Arathi on 2016/10/4.
 */
public class TextFileUtility {
    public static String ReadAll(String fileName, String encoding) {
        // File file = new File(fileName);
        URL url = TextFileUtility.class.getClassLoader().getResource(fileName);
        byte[] filecontent = null;
        try {
            File file = new File(url.toURI());
            Long filelength = file.length();
            filecontent = new byte[filelength.intValue()];
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e){
            e.printStackTrace();
        }
        try {
            return new String(filecontent, encoding);
        } catch (UnsupportedEncodingException e) {
            System.err.println("The OS does not support " + encoding);
            e.printStackTrace();
            return null;
        }
    }
}
